<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h3>访问子组件</h3>
      <!-- 需要在子组件标签上面添加一个ref属性 -->
      <!-- 在父组件里面用this.$refs.xxx的方式进行获取 -->
      <!-- ref只有在挂载完毕以后才能获取到 -->
      <child ref="abc"></child>

      <!-- 可以使用ref来获取dom元素 -->
      <input type="text" ref="inp" />
    </div>

    <script src="../Vue.js"></script>
    <script>
      const Child = {
        data() {
          return {
            count: 10,
          };
        },
        template: `
          <div>child组件</div>
        `,
      };
      new Vue({
        el: "#app",
        data: {},
        components: {
          Child,
        },
        mounted() {
          // console.log(this.$refs.abc);

          // console.log(document.querySelector("input"));
          console.log(this.$refs.inp);
        },
      });
    </script>
  </body>
</html>
